<template>
  <!-- 新闻列表 -->
  <div class="news-list-container">
    <ul class="mui-table-view">
      <li class="mui-table-view-cell mui-media" v-for="item in newsList" :key="item.id">
        <div class="mui-card">
          <div class="mui-card-content">
            <div class="mui-card-content-inner">
              <router-link :to="'/home/newsinfo/'+item.id">
                <img class="mui-media-object mui-pull-left" :src="item.img_url">
                <div class="mui-media-body">
                  <h2>{{ item.title }}}</h2>
                  <p class="mui-ellipsis">
                    <span>发表时间：{{ item.add_time | dateFormat}}</span>
                    <span>点击：{{ item.click }}次</span>
                  </p>
                </div>
              </router-link>
            </div>
          </div>
        </div>
      </li>
    </ul>
  </div>

  <!-- 评论板块 -->
</template>

<script>
import { Toast } from "mint-ui";

export default {
  data() {
    return {
      newsList: []
    };
  },
  created() {
    this.getNewsList();
  },
  methods: {
    getNewsList() {
      this.$http.get("api/getnewslist").then(res => {
        let data = res.body;
        if (data.status === 0) {
          this.newsList = data.message;
        } else {
          Toast("新闻列表获取失败");
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.news-list-container {
  .mui-table-view {
    li {
      h2 {
        font-size: 13px;
        color: #202020;
      }
      .mui-ellipsis {
        font-size: 12px;
        display: flex;
        justify-content: space-between;
        color: #2f68d6;
      }
    }
    .mui-table-view-cell {
      padding: 0;
      &::after {
        height: 0;
      }
    }
  }
}
</style>

